package com.lly.tboc.zhouyi.api

import com.lly.tboc.zhouyi.vo.GuaDatas
import okhttp3.HttpUrl
import okhttp3.Interceptor
import okhttp3.OkHttpClient
import retrofit2.Call
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.GET
import retrofit2.http.Query

interface ZhouyiApi {
    @GET("/android/zhouyi/data.json")
    fun getData(@Query("id") id: Int = 0): Call<GuaDatas>

    companion object {

        fun create(httpUrl: HttpUrl, logger: Interceptor): ZhouyiApi {

            val client = OkHttpClient.Builder()
                .addInterceptor(logger)
                .build()
            return Retrofit.Builder()
                .baseUrl(httpUrl)
                .client(client)
                .addConverterFactory(GsonConverterFactory.create())
                .build()
                .create(ZhouyiApi::class.java)
        }
    }

}